package Demo;

import java.io.File;
import java.io.RandomAccessFile;

public class Demo61 {
    public static void main(String[] args) throws Exception {
        File file = new File("d:\\test\\copy\\random.txt");
        RandomAccessFile raf = new RandomAccessFile(file, "rw");
        String[] names = new String[]{"zhangsan", "lisi", "wangwu"};
        int[] age = new int[]{96, 97, 98};
        for (int i = 0; i < names.length; i++) {
            raf.write(names[i].getBytes());
            raf.writeInt(age[i]);
        }
        {
            raf.seek(0);
            byte[] data = new byte[8];
            int len = raf.read(data);
            System.out.println(new String(data, 0, len) +"\t"+ raf.readInt());
        }
        {
            raf.seek(8);
            byte[] data=new byte[8];
            int len=raf.read(data);
            System.out.println(new String(data,0,len).trim()+"\t"+raf.readInt());
        }


        raf.close();
    }
}
